package com.dongliu.dao;

import com.dongliu.domain.Book;
import org.apache.ibatis.annotations.*;

import java.util.List;

// TODO 添加@Mapper
@Mapper
public interface BookDao {

    @Insert("insert into book values(null, #{type}, #{name}, #{description}, #{price}, #{number}, #{lentNumber})")
    public int save(Book book);

    @Update("update book set type=#{type}, name=#{name}, description=#{description}, number=#{number}, lentNumber=#{lentNumber}, price=#{price} where id=#{id}")
    public int update(Book book);

    @Delete("delete from book where id=#{id}")
    public int delete(Integer id);

    @Select("select * from book where id=#{id}")
    public Book getById(Integer id);

    @Select("select * from book where name like #{field} or type like #{field} or description like #{field}")
    public List<Book> getBooks(String field);

//    @Select("select * from book where name like #{name}")
//    public List<Book> getByName(String name);
//
//    @Select("select * from book where type like #{type}")
//    public List<Book> getByType(String type);
//
//    @Select("select * from book where description like #{description}")
//    public List<Book> getByDescription(String description);

    @Select("select * from book")
    public List<Book> getAll();

    @Select("select count(*) from book")
    public int getCount();
}
